package apis

import (
	"encoding/json"
	"github.com/gin-gonic/gin"
	"net/http"
	"zorm-learn/app/dbapi/model"
	"zorm-learn/app/dbapi/service"
	"zorm-learn/app/util"
)

var Routers = make([]func(*gin.RouterGroup), 0)

func init() {
	Routers = append(Routers, func(group *gin.RouterGroup) {
		routerGroup := group.Group("/dbapi")
		routerGroup.GET("insert", insert)
		routerGroup.GET("/test", func(context *gin.Context) {
			context.JSON(http.StatusOK, gin.H{"name": "servce2"})
		})
	})
}

func insert(context *gin.Context) {
	str := "{\"value\":\"2351\",\"collect_at\":1710915541000}"
	data := &model.TrendChartPointsStruct{}
	json.Unmarshal([]byte(str), data)
	data.Convert()
	service.SaveTrendChartPointsStruct(context, data)
	context.JSON(http.StatusOK, util.Success("success"))
}
